import numpy as np
import cv2 as cv

# 读取图像
image_path = "../boxs.png"
img = cv.imread(image_path)

# 检查图像是否成功读取
if img is None:
    print(f"Error: Image not found or unable to open the image at path: {image_path}")
    exit(1)

# 改变颜色空间  BGR -> Gray
img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
# 改变颜色空间  BGR -> HSV
img_hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)

# 打印img_hsv某个像素点的hsv的值
print(img_hsv[65,65]) # 112,227是roi_img.jpg的一个像素点的坐标
print(img_hsv[480,62])
print(img_hsv[469,355])
print(img_hsv[588,200])

# 根据以上选点的打印值，确定目标的hsv值范围
# [109 200 223]
# [109 215 184]
# [110 204 199]
# [110 191 216]
# lower_blue = np.array([105,190,180])
# upper_blue = np.array([115,220,230])

cv.imshow("LingXiao", img)
# cv.imshow("gray", img_gray)
# cv.imshow("hsv", img_hsv)


# 等待按键
print("Press ESC to close the windows.")
while True:
    key = cv.waitKey(0)
    if key == 27:  # ESC 键
        break
    else:
        print(f"Key pressed: {key}")

    # 关闭所有窗口
    cv.destroyAllWindows()


